﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//
using CredisysTriunfadores.Repository.Prestamos.Interfaz;
using CredisysTriunfadores.BusinessEntites.Prestamos;

namespace CredisysTriunfadores.Repository.Prestamos
{
    public class PrestamoAD:MasterRepository,IPrestamoAD
    {
        public IEnumerable<Prestamo> GetAllPrestamos()
        {
            var query = from pr in Context.Prestamos
                select pr;

            return query.ToList();

        }
        
        public Prestamo AddPrestamo(Prestamo prestamo)
        {
            Context.Prestamos.Add(prestamo);
            Context.SaveChanges();
            return null;
        }


        public IEnumerable<Prestamo> GetAllPrestamosByCriterio(string criterio)
        {

            var query = from c in Context.Prestamos
                        select c;
            if (criterio != null && criterio != string.Empty)
            {
                query = from c in query
                        where c.PeriodoPago.ToUpper().Contains(criterio.ToUpper())
                        select c;
            }
            return query.ToList();
        }
    }
}
